using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.ServiceProcess;
using System.Text;
using System.Windows.Forms;

using GuerillaProgrammer.FileProcessor;
using GuerillaProgrammer.FileProcessor.Settings;

namespace FPInstaller
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Get user ID
            frmUserID userID = new frmUserID();
            if (DialogResult.OK == userID.ShowDialog())
            {
                //I need to get the path to the application
                string appFolder = @"D:\SourceCode\clients\GuerillaProgrammer\Products\FileProcessor\FileProcessorService\bin\Debug\";
                string app = Path.Combine(appFolder, "FileProcessorService.exe");

                //setup service
                if (false == FPServiceInstaller.InstallService(userID.UserName, userID.Password, app))
                {
                    //We don't really care but the user should be told
                    MessageBox.Show("The service failed to install.\nYou can manually install it instead.\nSetup will proceed.");

                }

                //select archive directory
                FolderBrowserDialog fbd = new FolderBrowserDialog();
                string archiveFolder = Path.Combine(appFolder, "Archive");
                if (DialogResult.OK == fbd.ShowDialog())
                {
                    archiveFolder = fbd.SelectedPath;
                }

                string assemblyFolder = Path.Combine(appFolder, "Assemblies");
                FPServiceInstaller.WriteConfiguration(appFolder, archiveFolder, assemblyFolder);

            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            FPServiceInstaller.WriteDesignerConfiguration("C:\\temp", "C:\\temp");
        }

        private void button3_Click(object sender, EventArgs e)
        {
            string appFolder = @"C:\Program Files\GuerillaProgrammer\File Processor";
            string assemblyFolder = Path.Combine(appFolder, "Assemblies");
            FPServiceInstaller.WriteConfiguration(appFolder, "C:\\temp", assemblyFolder);


        }

        private void button4_Click(object sender, EventArgs e)
        {
            string appFolder = @"C:\Program Files\Engine Of Progress\Grinder";
            string[] args = new string[0];

            FPServiceInstaller.DoInstall(args);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            frmArchiveDirectory archive = new frmArchiveDirectory();
            if (DialogResult.OK == archive.ShowDialog())
            {
            }
        }
    }
}